(function(K) {

    var doc = document,
        D = K.DOM,
        E = K.Event,
        J = K.JSON,
        IO = K.IO,
        handle;

    handle = {
        del: function(ev) {

            ev.preventDefault();

            var host = handle,
                node = this.getDOMNode();

            handle.send(node, null, '<span class="ok">删除成功</span>');

        },

        act: function(ev) {

            ev.preventDefault();

            var host = handle,
                node = this.getDOMNode();

            handle.send(node, null, '<span class="ok">成功</span>');

        },

        send: function(node, data, content, callback) {

            var d = J.parse(node.getAttribute('data-config'));

            if (data) {

                d = K.merge(data, d);

            }

            IO({

                type: 'post',
                dataType: 'json',
                url: node.getAttribute('data-url'),
                data: d,
                success: function(data) {

                    if (data && '1' === data.status) {

                        if (callback) {
                            callback();
                        }

                        K.use('overlay', function() {

                            var overlay = new K.Overlay({

                                content: content

                            });

                            overlay.render();
                            overlay.show();
                            overlay.align(node, ['tr', 'tl']);
                            setTimeout(location.replace(location), 2000);

                        });

                    } else {
                        data.msg && alert(data.msg);
                    }

                }

            });

        },

        reload: function() {

            location.replace(location);

        },

        attachEvent: function() {

            var host = this;
            K.all('.J_RemoveMonInfo').on('click', host.del);
            K.all('.J_TriggerPause').on('click', host.act);
            K.all('.J_TriggerPauseAll').on('click', host.act);
            K.all('.J_TriggerResumeAll').on('click', host.act);
            K.all('.J_TriggerResume').on('click', host.act);
            K.all('.J_TriggerRemove').on('click', host.del);
            K.all('.J_Remove').on('click', host.del);
        },

        init: function() {

            var host = this;

            host.attachEvent();

            return host;

        }

    };

    return handle.init();

})(KISSY);